<template>
  <div style="display: flex; justify-content: space-between">
    <div style="display: flex; align-items: center">
      <div class="p-flex">
        <span style="width: 60px">搜索</span>
        <el-input v-model="tableAddr" maxlength="44" @keyup.enter="inputSearch()"></el-input>
      </div>
      <div class="p-flex">
        <span style="width: 100px">轮播间隔（秒）</span>
        <el-input-number v-model="secondNum" :precision="0" :step="5" :min="1" :max="60"/>
      </div>
      <div class="p-flex">
        <el-checkbox v-model="checkedlook">只看已选（{{ checked.length }}）</el-checkbox>
      </div>
    </div>
    <div>
      <el-button type="primary" @click="startVideoPlay()">开始轮播</el-button>
    </div>
  </div>

  <p style="color: red">提示：4G相机流量消耗过大，不支持轮播！</p>

  <el-table :data="crmListall" row-key="id" @select="selectChange" @select-all="selectAllChange"
            @selection-change="handleSelectionChange" height="500">
    <el-table-column type="selection" width="55"/>
    <el-table-column property="addr" label="通道名称"/>
    <el-table-column property="ip" label="ip"/>
    <el-table-column property="gbsCode" label="设备编号"/>
  </el-table>
</template>

<script>
import baseService from "@/service/baseService";
import {removeNodesByType} from "@/utils/treedatatreating";
import {ElMessage} from "element-plus";

export default {
  data() {
    return {
      tableData: [], //初始数据
      crmListall: [], //筛选展示数据
      checkAll: false,
      checked: [],
      tableAddr: "",
      secondNum: 10,
      checkedlook: false,
      cirblooun: false,
      setIntervalTd: null,
    }
  },
  watch: {
    checkedlook() {
      if (this.checkedlook) {
        this.crmListall = this.checked;
      } else {
        this.crmListall = this.tableData;
      }
    }
  },
  mounted() {
    this.getNvrTree();
  },
  methods: {
    getNvrTree() {
      this.tableData = [];
      baseService.get("/Camera/kxcamera/getList").then((res) => {
        let terrList = removeNodesByType(res.data, "hk-mn-zt");
        this.tableData = terrList;
        this.crmListall = this.tableData;
      });
    },
    inputSearch() {
      this.crmListall = this.fuzzySearch(this.tableAddr, this.tableData);
    },
    fuzzySearch(keyword, data) {
      return data.filter((item) => item.addr.includes(keyword));
    },
    selectChange(selection) {
      this.checked = selection;
    },
    selectAllChange(selection) {
      this.checked = selection;
    },
    handleSelectionChange(selection) {
      //处理数据
      //。。。
      // checked.value = selection.map((item) => item.id);
    },
    startVideoPlay() {
      if (this.checked <= 0) {
        ElMessage.warning("请先选择轮播相机！");
        return;
      }
      this.$emit('startVideoPlay', {data: this.checked, time: this.secondNum});
    }
  }
}
</script>

<style scoped lang="scss">
.p-flex {
  display: flex;
  align-items: center;
  padding-right: 20px;
}
</style>
